package com.snailxr.base.task.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import com.snailxr.base.task.dao.APIObjDao;
import com.snailxr.base.task.domain.APIObj;
import com.snailxr.base.task.domain.DataDictionary;
@Repository("apiObjDaoImpl")
public class APIObjDaoImpl implements APIObjDao{
	public final Logger log = Logger.getLogger(this.getClass());
	@Resource(name="mongoTemplate")
	private MongoTemplate mongoTemplate;
	private String collectionName;//集合名

	/**
	 * 根据接口标识查找
	 * @see com.snailxr.base.task.dao.APIObjDao#selectById(java.lang.String)
	 */
	@Override
	public APIObj selectByPrimaryKey(int apiId) {
		Criteria ceritera = Criteria.where("apiId").is(apiId);
		Query query = new Query(ceritera);
		APIObj apiObj = mongoTemplate.findOne(query, APIObj.class,collectionName);
		return apiObj;
	}

	/**
	 * 查询全部接口
	 */
	@Override
	public List<APIObj> selectAll() {
		List<APIObj> apiObjs = mongoTemplate.findAll(APIObj.class);
		return apiObjs;
	}

	/**
	 * 插入一条
	 */
	@Override
	public void insert(APIObj apiObj) {
		mongoTemplate.insert(apiObj);
	}

	/**
	 * 删除
	 */
	@Override
	public void delete(int apiId) {
		mongoTemplate.remove(new Query(Criteria.where("apiId").is(apiId)), APIObj.class);
	}
	
	public MongoTemplate getMongoTemplate() {
		return mongoTemplate;
	}

	public void setMongoTemplate(MongoTemplate mongoTemplate) {
		this.mongoTemplate = mongoTemplate;
	}

	public String getCollectionName() {
		return collectionName;
	}

	public void setCollectionName(String collectionName) {
		this.collectionName = collectionName;
	}
	
}
